package com.lineage.server.timecontroller.pc;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.thread.PcOtherThreadPool;
import com.lineage.server.world.WorldDragonKnight;
import java.util.Collection;
import java.util.Iterator;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HprTimerDragonKnight extends TimerTask {
  private static final Log _log = LogFactory.getLog(HprTimerDragonKnight.class);
  
  private ScheduledFuture<?> _timer;
  
  public void start() {
    int timeMillis = 3000;
    this._timer = PcOtherThreadPool.get().scheduleAtFixedRate(this, 3000L, 3000L);
  }
  
  public void run() {
    try {
      Collection<L1PcInstance> allPc = WorldDragonKnight.get().all();
      if (allPc.isEmpty())
        return; 
      Iterator<L1PcInstance> iter = allPc.iterator();
      while (iter.hasNext()) {
        L1PcInstance tgpc = iter.next();
        HprExecutor hpr = HprExecutor.get();
        if (hpr.check(tgpc)) {
          hpr.checkRegenHp(tgpc);
          Thread.sleep(1L);
        } 
      } 
    } catch (Exception e) {
      _log.error("Pc(龙骑) HP自然回复时间轴异常重启", e);
      PcOtherThreadPool.get().cancel(this._timer, false);
      HprTimerDragonKnight hprDK = new HprTimerDragonKnight();
      hprDK.start();
    } 
  }
}
